package gui.event;

import java.awt.Point;
import java.awt.Polygon;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;
import gui.GameConstants;

import dal.object.MapObject;

public class SwitchObject extends MouseAdapter {
	private Vector<MapObject> moVector;
	private Polygon hexagon;
	
	public SwitchObject(Vector<MapObject> moVector){
		Point A = new Point(GameConstants.picWidth50, 0);
		Point B = new Point(0, GameConstants.picHeight25);
		Point C = new Point(0, GameConstants.picHeight75);
		Point D = new Point(A.x, GameConstants.picHeight100);
		Point E = new Point(GameConstants.picWidth100, C.y);
		Point F = new Point(GameConstants.picWidth100, B.y);
		
		hexagon = new Polygon();
		hexagon.addPoint(A.x, A.y);
		hexagon.addPoint(B.x, B.y);
		hexagon.addPoint(C.x, C.y);
		hexagon.addPoint(D.x, D.y);
		hexagon.addPoint(E.x, E.y);
		hexagon.addPoint(F.x, F.y);
		
		this.moVector = moVector;
	}
	
	public void mousePressed(MouseEvent mouse) {
		MapObject selected = null;
		
		for(MapObject mo : moVector){
			Polygon poly = new Polygon(hexagon.xpoints, hexagon.ypoints, hexagon.npoints);
			poly.translate(mo.getLocation().x, mo.getLocation().y);
			
			if( poly.contains(mouse.getPoint()) ){
				selected = mo;
				break;
			}
		}
		
		if(selected != null) {
			System.out.println(selected.getLocation());
		} else {
			System.out.println("out of bound!");
		}
	}
}
